<?php include HEADER; ?>
<?php
	$trangthai_search = (isset($_REQUEST['trangthai'])) ? $_REQUEST['trangthai'] : 'all';
	$idtivi_search = (isset($_REQUEST['tivi_id'])) ? $_REQUEST['tivi_id'] : 'all';
	$kichthuoc_search = (isset($_REQUEST['kichthuoc'])) ? $_REQUEST['kichthuoc'] : 'all';
	$giamin_search = (isset($_REQUEST['giamin'])) ? $_REQUEST['giamin'] : '';
	$giamax_search = (isset($_REQUEST['giamax'])) ? $_REQUEST['giamax'] : '';
	$soluongf_search = (isset($_REQUEST['soluongf'])) ? $_REQUEST['soluongf'] : '';
	$soluongt_search = (isset($_REQUEST['soluongt'])) ? $_REQUEST['soluongt'] : '';
	$sapxep = (isset($_REQUEST['sapxep'])) ? $_REQUEST['sapxep'] : '';
	$by = (isset($_REQUEST['by'])) ? $_REQUEST['by'] : '';
?>
<table id="search" style="margin-bottom:20px;">
	<tr>
		<td>
			<select id="stivi" data-placeholder="Tìm theo tên tivi..." class="chosen-select" style="width:208px;" tabindex="2">
				<option value="all">Tìm theo tên tivi...</option>
			<?php
				$tiviModel = new tivi();
				$alltivi = $tiviModel->getTiviByWhere('','');
				foreach($alltivi as $item){
			?>
					<option value="<?php echo $item->id?>" <?php if($item->id == $idtivi_search) echo 'selected="selected"'; ?>><?php echo $item->TenTivi?></option>
			<?php
				}
			?>
			</select>
			<select class="chosen-select" id="skichthuoc" style="width:208px;" data-placeholder="Tìm theo kích thước..." >
				<option value="all">Tìm theo kích thước...</option>
				<?php
					//$tiviModel = new tivi();
					$lstKichThuoc = $tiviModel->getKichThuocTivi(); 
					foreach($lstKichThuoc as $item){
				?>
						<option value="<?php echo $item->KichThuoc?>" <?php if($item->KichThuoc == $kichthuoc_search) echo 'selected="selected"'; ?>><?php echo $item->KichThuoc?></option>
				<?php
				}
			?>
			</select>
			
			<select id="strangthai" data-placeholder="Tìm theo trạng thái..." class="chosen-select" style="width:208px;" tabindex="2">
				<option value="all">Tìm theo trạng thái...</option>
				
				<option value="1" <?php if($trangthai_search == '1') echo 'selected="selected"'; ?>>Hiện</option>
				<option value="0" <?php if($trangthai_search == '0') echo 'selected="selected"'; ?>>Ẩn</option>
			
			</select>
			<select id="ssapxep" data-placeholder="Sắp xếp theo..." class="chosen-select" style="width:208px;" tabindex="2">
				<option value="">Sắp xếp theo...</option>
				<option value="TenTivi" <?php if($sapxep == 'TenTivi') echo 'selected="selected"'; ?>>Tên tivi</option>
				<option value="GiaBan" <?php if($sapxep == 'GiaBan') echo 'selected="selected"'; ?>>Giá bán</option>
				<option value="KichThuoc" <?php if($sapxep == 'KichThuoc') echo 'selected="selected"'; ?>>Kích thước tivi</option>
				<option value="SoLuong" <?php if($sapxep == 'SoLuong') echo 'selected="selected"'; ?>>Số lượng</option>
				<option value="t.TrangThai" <?php if($sapxep == 't.TrangThai') echo 'selected="selected"'; ?>>Trạng thái</option>
			</select>
			<select id="sby" data-placeholder="" class="chosen-select" style="width:78px;" tabindex="2">
				<option value="desc" <?php if($by == 'desc') echo 'selected="selected"'; ?>>Giảm</option>
				<option value="asc" <?php if($by == 'asc') echo 'selected="selected"'; ?>>Tăng</option>
			</select>
			<br /><br />
			<input id="tGiaMin" type="text" class="text num price" placeholder="Giá trị từ..." value="<?php echo $giamin_search ?>"  />
			<input id="tGiaMax" type="text" class="text num price" placeholder="Giá trị đến..." value="<?php echo $giamax_search ?>"/>
			<input id="tsoluongf" type="text" class="text num" placeholder="Số lượng từ..." value="<?php echo $soluongf_search ?>"  />
			<input id="tsoluongt" type="text" class="text num" placeholder="Số lượng đến..." value="<?php echo $soluongt_search ?>"  />
			<span style="position: relative;top:-2px;">
				<button id="btnsearch" type="button" class="btn btn-default">
					<img src="<?php echo __URL_BASE ?>img/search.png" width="15px" />
				</button>
				<button id="btnclear" type="button" class="btn btn-default" style="margin-left: -8px;border-radius: 0 4px 4px 0;">
					<img src="<?php echo __URL_BASE ?>img/x.png" width="15px" />
				</button>
			</span>
		</td>
</table>
<?php
	//get request link
	$request = ''; 
	$dem = 1;
	if($_REQUEST){
		foreach($_REQUEST as $k=>$v){
			if($dem == 1){
				$request .= '?'.$k.'='.$v;
			}
			else{
				$request .= '&'.$k.'='.$v;
			}
			$dem++;
		}
		
	}
	//echo $request; 
?>
<form method="post" action="<?php echo __URL_BASE ?>index.php?rt=admin_tivi/action_group">
<input type="hidden" name="request" value="<?php echo $request; ?>" />
<div class="Control">
<ul style="margin-top:4px">
  <li> <a href="<?php echo __URL_BASE ?>index.php?rt=admin_tivi/edit"><label class="vadd" style="cursor:pointer">Thêm mới</label></a> </li>
 <li> <button class="vdelete" style="border:none;cursor:pointer" name="delete" onclick="return confirm('chắc chắn xóa?');" >Xóa</button> </li>
  <li> <button class="vrefresh" style="border:none;cursor:pointer" name="active">Hiện</button> </li>
  <li> <button class="vrefresh" style="border:none;cursor:pointer" name="deactive">Ẩn</button> </li>
  <!--<li> <a class="vback" href="javascript:void(0);" onclick="window.history.go(-1);">Trở lại</a> </li>-->
</ul>
</div>
<table class="TableView" cellspacing="1">
<tr class="trHeader">
    <td><input type="checkbox" id="chkSelectAll" onclick="checkAll(this)" /></td>
    <td>Hình ảnh</td>
    <td style="width:300px">Tên Tivi</td>
    <td>Kích thước</td>
    <td style="width:110px">Giá</td>
    <td>Số lượng</td>
    <td>Trạng thái</td>
    <td width="70px"></td>
    
</tr>
<?php
    $i = 0;
	if($lstTivi) :
		foreach($lstTivi as $item){
			if($i%2==0){
	?>		
				<tr class="trOdd">
	
				
	<?php	
			}
			else{
	?>
				<tr class="trEven">
	<?php		
			}
	?>
	<td ><input type="checkbox" id="chkSelect<?php echo $i?>" name="chkSelect['<?php echo $item->id ?>']" onclick="Check_Click(this)" /></td>
	<td style="text-align:left"><img src="<?php echo __URL_BASE.'images/'.utility::setImageThumb($item->Images,$item->Images2,$item->Images3,$item->Images4,$item->Images5); ?>" style="max-width:180px;max-height:50px" /></td>
	<td><?php echo $item->TenTivi ?></td>
	<td style="padding: 0 10px;"><span style="font-weight:bold">Kích Thước:</span> <?php echo $item->KichThuoc ?> inches
		<br /><span style="font-weight:bold">Độ phân giải:</span> <?php echo $item->PhanGiai ?>
	</td>
	<td style="padding:0 5px;"><span><?php echo number_format($item->GiaBan,0,'','.')?> đ</span>
		<br /><span style="text-decoration:line-through;color:#999"><?php echo number_format($item->GiaThat,0,'','.')?> đ</span>
	</td>
	<td align="right"><?php echo $item->SoLuong?></td>
	<td align="center"><?php if($item->TrangThai == "1"){ echo "Hiện";} else{ echo "Ẩn";} ?></td>
	<td align="center"><a href="<?php echo __URL_BASE.'index.php?rt=admin_tivi/edit&tivi_id='.$item->id ?>"><img src="<?php echo __URL_BASE ?>images/edit.png" style="cursor:pointer;" class="edit" /></a>
	<a href="<?php echo __URL_BASE.'index.php?rt=admin_tivi/delete&tivi_id='.$item->id ?>" onclick="return confirm('Bạn muốn xóa?');"><img src="<?php echo __URL_BASE ?>images/delete.png" /></a></td>
	
	</tr>	
	<?php
			$i++;
		}
	endif;
?>


</table>
<div class="Control">
<ul style="margin-top:4px">
  <li> <a href="<?php echo __URL_BASE ?>index.php?rt=admin_tivi/edit"><label class="vadd" style="cursor:pointer">Thêm mới</label></a> </li>
 <li> <button class="vdelete" style="border:none;cursor:pointer" name="delete" onclick="return confirm('chắc chắn xóa?');">Xóa</button> </li>
  <li> <button class="vrefresh" style="border:none;cursor:pointer" name="active">Hiện</button> </li>
  <li> <button class="vrefresh" style="border:none;cursor:pointer" name="deactive">Ẩn</button> </li>
  <!--<li> <a class="vback" href="javascript:void(0);" onclick="window.history.go(-1);">Trở lại</a> </li>-->
</ul>
</div>
</form>
<?php utility::getPagination_admin($pages); ?>
<?php include FOOTER; ?>
<script>
	$(document).ready(function(){
		$("#btnsearch").click(function(){
			request = '';
			if($("#stivi").val() != 'all') request += '&tivi_id='+$("#stivi").val() ;
			if($("#strangthai").val() != 'all') request += '&trangthai='+$("#strangthai").val() ;
			if($("#skichthuoc").val() != 'all') request += '&kichthuoc='+$("#skichthuoc").val() ;
			if($("#tGiaMin").val() != '') request += '&giamin='+$("#tGiaMin").val() ;
			if($("#tGiaMax").val() != '') request += '&giamax='+$("#tGiaMax").val() ;
			if($("#tsoluongf").val() != '') request += '&soluongf='+$("#tsoluongf").val() ;
			if($("#tsoluongt").val() != '') request += '&soluongt='+$("#tsoluongt").val() ;
			if($("#ssapxep").val() != '') request += '&sapxep='+$("#ssapxep").val() ;
			if($("#sby").val() != '') request += '&by='+$("#sby").val() ;
			location.href = '<?php echo __URL_BASE ?>index.php?rt=admin_tivi'+request;
		});
		
		$("#btnclear").click(function(){
			location.href = '<?php echo __URL_BASE ?>index.php?rt=admin_tivi';
		});
	});
	
	
</script>
